package com.klangner.go.app;

import java.awt.*;

import com.klangner.go.app.strategy.AlphaBetaPruningGoStrategy;
import com.klangner.go.app.strategy.IGoStrategy;

public class MinMaxSettingsFrame extends GeneralOKCancel {

    Label label         = null;
    TextField textField = null;
    Panel panel         = null;

public MinMaxSettingsFrame(IGoStrategy theStrategy) {
    super();

    label = new Label();
    textField = new TextField();
    panel = new Panel();

    try  {
        _jbInit();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    strategy = (AlphaBetaPruningGoStrategy)theStrategy;
    loadData();
}

private void _jbInit() throws Exception {
    this.add(panel, BorderLayout.CENTER);

    label.setText("Maximum Search Depth:");
    textField.setText("0");

    panel.add(label);
    panel.add(textField);
}

protected void loadData() {
    if (strategy != null) {
        textField.setText(new Integer(strategy.getMaxDepth()).toString());
    }
}

protected void saveChanges() {
    if (strategy != null) {
        try {
            int maxDepth = Integer.parseInt(textField.getText());
            strategy.setMaxDepth(maxDepth);
        }
        catch (NumberFormatException e) {}
    }
}

  protected AlphaBetaPruningGoStrategy strategy = null;
}

